package com.jtjrenren.android.taxi.passenger.core.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.base.BaseRcyAdapter;
import com.jtjrenren.android.taxi.passenger.bean.api.Complaint;

/**
 * Created by Administrator on 2016/2/19.
 */
public class CompaintSugAdapter extends BaseRcyAdapter<Complaint.DatalistEntity> {
    public int selectItem = -1;

    public CompaintSugAdapter(Context context) {
        super(context);
    }

    @Override
    public RecyclerView.ViewHolder getItemViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.item_compaint_list, parent, false);
        return new CompaintViewHolder(view);
    }

    @Override
    public void onBindItemViewHolder(RecyclerView.ViewHolder holder, int position) {
        Complaint.DatalistEntity info = list.get(position);
        CompaintViewHolder cholder = (CompaintViewHolder) holder;

        cholder.tv_desc.setText(info.getValue());
        if (selectItem == position)
            cholder.cb_choose.setChecked(true);
        else
            cholder.cb_choose.setChecked(false);

    }

    public class CompaintViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_desc;
        private CheckBox cb_choose;

        public CompaintViewHolder(View itemView) {
            super(itemView);
            tv_desc = (TextView) itemView.findViewById(R.id.item_comlist_desc);
            cb_choose = (CheckBox) itemView.findViewById(R.id.item_comlist_cb);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    selectItem = getAdapterPosition();
                    notifyDataSetChanged();
                }
            });
        }
    }
}
